package com.tengju.bff.interfaces.app.announcement;

import com.tengju.bff.interfaces.app.announcement.vo.AnnounceVO;
import com.tengju.bff.interfaces.app.announcement.vo.PageAnnounceArticleVO;
import com.tengju.bff.interfaces.manage.member.article.facade.ArticleFacade;
import com.tengju.bff.interfaces.manage.member.article.vo.ArticleContextVO;
import com.tengju.bff.interfaces.manage.member.article.vo.GetArticleForm;
import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.servlet.NotTokenValid;
import com.tengju.support.application.article.ArticleService;
import com.tengju.support.domain.model.article.ArticleId;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

@Validated
@Slf4j
@RestController
@Api(tags = "app合规公告")
@RequestMapping(value = "/app/compliance/announcement")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ComplianceAnnounceController {

    private final ArticleFacade articleFacade;
    private final ArticleService articleService;


    @NotTokenValid
    @ApiOperation(value = "获取文章上下文", notes = "获取文章上下文")
    @RequestMapping(value = "getContext", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<ArticleContextVO> getArticleContext(
            @NotNull(message = "文章id不能为空") @RequestParam Long articleId) {
        return ApiResponse
                .newSuccess(articleFacade.getArticleContext(new ArticleId(articleId)));

    }

    @ApiOperation(value = "分页查询文章列表", notes = "分页查询文章列表")
    @RequestMapping(value = "page/article/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<PageAnnounceArticleVO> getAnnounceArticleByPage(GetArticleForm form) {
        return ApiResponse.newSuccess(articleFacade.getAnnounceArticleByPage(form));
    }

    @ApiOperation(value = "上报文章浏览量", notes = "上报文章浏览量")
    @RequestMapping(value = "article/view/count", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<Integer> updateArticleViewCnt(
            @NotNull(message = "文章id不能为空") @RequestParam Long articleId) {

        return ApiResponse.newSuccess(0);


    }

    @ApiOperation(value = "公告类型列表", notes = "公告类型列表")
    @RequestMapping(value = "article/announce/type/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<List<AnnounceVO>> getAnnounceType() {
        return ApiResponse.newSuccess(articleFacade.getAnnounceType());
    }

}
